﻿using HuaweiCloud.Dotnet.Samples.ESports.Main.Dtos;
using HuaweiCloud.Dotnet.Samples.ESports.Main.Service;
using Microsoft.AspNetCore.Mvc;

namespace HuaweiCloud.Dotnet.Samples.ESports.Main.Controllers
{
    [Route("api-main/v1/[controller]")]
    [Route("api/v1/[controller]")]
    [ApiController]
    public class EventsController : ControllerBase
    {
        private readonly ICommunityEventsService _service;
        public EventsController(ICommunityEventsService service)
        {
            _service = service;
        }

        [HttpGet]
        public async Task<ActionResult<IEnumerable<CommunityEventsDto>>> Get()
        {
            return Ok(await _service.ListAsync());
        }

        [HttpGet("{id}")]
        public async Task<ActionResult> Get(Guid id)
        {
            return Ok(await _service.GetAsync(id));
        }

        [HttpPost]
        public async Task<ActionResult> Post([FromBody] CreateCommunityEventsDto dto)
        {
            await _service.AddAsync(dto);
            return Created("", null);
        }

        [HttpPut("{id}")]
        public async Task<ActionResult> Put(Guid id, [FromBody] UpdateCommunityEventsDto dto)
        {
            dto.Id = id;
            await _service.UpdateAsync(dto);
            return NoContent();
        }

        [HttpDelete("{id}")]
        public async Task<ActionResult> Delete(Guid id)
        {
            await _service.DeleteAsync(id);
            return NoContent();
        }
    }
}
